package org.jash.shop2112.utils

import android.content.Context
import androidx.room.Room
import androidx.room.RoomDatabase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import org.jash.shop2112.database.GoodsDao
import org.jash.shop2112.database.ShopDatabase
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ModelFactory {
    @Singleton
    @Provides
    fun getService() = retrofit.create(APIService::class.java)
    @Singleton
    @Provides
    fun getDB(@ApplicationContext app:Context):ShopDatabase {
        return Room.databaseBuilder(app, ShopDatabase::class.java, "shop")
            .fallbackToDestructiveMigration()
            .build()
    }
    @Singleton
    @Provides
    fun getGoodsDao(db:ShopDatabase):GoodsDao = db.getGoodsDao()
}